package controlflow

/**
 * Created by CJJ on 2017/7/14.
 */
fun main(args: Array<String>) {

    label()
}


//控制语句
fun When(): Unit {
    val x = 10
    when (x) {
        11 -> print(x)
        in 1..10 -> {
            print(x)
            print(x + 1)
        }
        else ->
            print("bad luck")
    }

}

fun has(x: Any) = when (x) {
    is String -> true
    in 1..10 -> false
    else -> false

}


//标签
fun label() {
    println("loop label")
    loop@ for (i in 1..5)
        for (j in 1..5)
            if (j >= 2)
                break
            else println("i = $i j=$j")

    loop@ for (i in 1..5)
        (1..5)
                .filter { it < 2 }
                .forEach { println("i = $i j=$it") }


    println("forEach label")
    val ints = Array(5, { i -> i })
    ints.forEach {
        if (it == 2)
            return@forEach
        println(it)
    }
}